package com.picket.controller.users.predictions;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.picket.domain.UserPrediction;


public class UserPredForm {
        private String selected;
        private long eventId;
        private long userPoolId;
		public List<UserPrediction> userPreds = new ArrayList<UserPrediction>();
		public List<String> userPredStr = new ArrayList<String>();
		public List<UserPrediction> toBePredicted = new ArrayList<UserPrediction>();
		public List<UserPrediction> history = new ArrayList<UserPrediction>();
        public List<UserPrediction> getToBePredicted() {
			return toBePredicted;
		}
		public void setToBePredicted(List<UserPrediction> toBePredicted) {
			this.toBePredicted = toBePredicted;
		}
		public List<UserPrediction> getHistory() {
			return history;
		}
		public void setHistory(List<UserPrediction> history) {
			this.history = history;
		}
		public void setUserPreds(List<UserPrediction> userPreds) {
			this.userPreds = userPreds;
		}
		public long getUserPoolId() {
			return userPoolId;
		}
		public void setUserPoolId(long userPoolId) {
			this.userPoolId = userPoolId;
		}
		public long getEventId() {
			return eventId;
		}
		public void setEventId(long eventId) {
			this.eventId = eventId;
		}

		
		public List<String> getUserPredStr() {
			return userPredStr;
		}
		public void setUserPredStr(List<String> userPredStr) {
			this.userPredStr = userPredStr;
		}
		public void addUserPredStr(String userPredStr) {
			this.userPredStr.add(userPredStr);
		}
		public List<UserPrediction> getUserPreds() {
			return userPreds;
		}
		public void setUserPreds(ArrayList<UserPrediction> userPreds) {
			this.userPreds = userPreds;
		}
		public String getSelected() {
			return selected;
		}
		public void setSelected(String selected) {
			this.selected = selected;
		}
		
		public void clearData(){
			this.userPredStr.clear();
			this.userPreds.clear();
			toBePredicted.clear();
			history.clear();
		}
		
		//First time form is accessed
		public void initialize2(ArrayList<UserPrediction> userPreds) {
			setUserPreds(userPreds);
			for(UserPrediction userPred : this.getUserPreds()){
				Calendar currentDateTime = Calendar.getInstance();
				if(isHistory(currentDateTime.getTime(),userPred.getMatchDateTime())){
					history.add(userPred);
					
				}else{
					
					toBePredicted.add(userPred);
					userPredStr.add(userPred.getMatchPrediction());
				}
			}	
			/*
			for(UserPrediction userPred : this.getUserPreds()){
				userPredStr.add(userPred.getMatchPrediction());
			}*/
		}

		private boolean isHistory(Date currentDateTime,
				Date matchDateTimeAsCalendar) {
			return currentDateTime.after(matchDateTimeAsCalendar);
		}
		
}